package mobel

import (
	"gorm.io/gorm"
	"message-queue_0826/global"
	"time"
)

type User struct {
	Id        uint32         `gorm:"column:id;type:int UNSIGNED;comment:用户ID;primaryKey;not null;" json:"id"`                                  // 用户ID
	Mobile    string         `gorm:"column:mobile;type:char(11);comment:账号;not null;" json:"mobile"`                                           // 账号
	CreatedAt time.Time      `gorm:"column:created_at;type:datetime(3);comment:注册时间;not null;default:CURRENT_TIMESTAMP(3);" json:"created_at"` // 注册时间
	UpdatedAt time.Time      `gorm:"column:updated_at;type:datetime(3);not null;default:CURRENT_TIMESTAMP(3);" json:"updated_at"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;type:datetime(3);default:NULL;" json:"deleted_at"`
}

func (u User) TableName() string {
	return "user"
}

// 注册
func (u *User) Register() error {
	return global.DB.Create(&u).Error
}

// 登陆
func (u *User) Login() error {
	return global.DB.Where("mobile = ?", u.Mobile).Find(&u).Error
}
